#include "stdio.h"
#include "string.h"

main()
{
	int n,num;
	int sm[28][28];
	int enough,time,readtime;
	int i,j,k,error,p,q;
	char xiao[5],x,y;
	
	
	scanf("%d%d",&n,&num);
	while (n||num)
	{
		memset(sm,0,sizeof(sm));  /* init start */
		time=n;
		for (i=1;i<=n;i++) sm[i][i]=1;
		enough=(n+1)*n/2; 
	        readtime=0;	/* init end */
		
		for (j=1;j<=num;j++)
		{
			error=0;
			scanf("%s",xiao);readtime++;
			x=xiao[0]-'A'+1;
			y=xiao[2]-'A'+1;
			if (sm[y][x]==1)
			{
				error=j;
				break;
			}
			else
			{
				for (p=1;p<=n;p++)
				{
					for (q=1;q<=n;q++)
					if ((sm[p][x])&&(sm[y][q]))
					{
						if (sm[p][q]!=1)
						{
							sm[p][q]=1;
							++time;
							if (sm[q][p]) error=j;
							if ((time==enough)||error) break;
						}
						
					}
					if ((time==enough)||error) break;
				}
				if ((time==enough)||error) break;
										
			}
			
		}
				
		if (error) printf("Inconsistency found after %d relations.\n",readtime);
		else if (time<enough) printf("Sorted sequence cannot be determined.\n");                         else 
		{
			printf("Sorted sequence determined after %d relations: ",readtime);
			for (i=1;i<=n;i++)
			{
				k=0;
				for (j=1;j<=n;j++) k+=sm[j][i];
				sm[0][i]=k;
			}
			for (i=1;i<=n;i++)
			{
				for (j=1;j<=n;j++) 
					if (sm[0][j]==i) printf("%c",j-1+'A');
			}
			printf(".\n");
		}
		
			

		while (readtime<num) 
		{
			scanf("%s",xiao);
			readtime++;
		}
		scanf("%d%d",&n,&num);
	}

	
}














